package org.zjt.scala.domain

/**
  *
  * Description:
  *
  * 继承 ： 特征（类似接口）、类    extends:
  *
  *
  * public属性：   instance val field
  *
  *               private val age:Int
  *
  * 类型的别名：
  *               type al = String
  *
  * @author juntao.zhang
  *         Date: 2018-06-25 下午6:03
  * @see
  */

trait Alive {

  type al = String

  def eat():Unit

  def action():al

}



class Animal(age:Int) extends Alive{


  override def eat(): Unit = {
    println("--------eating---------")
  }

  override def action(): al = {
    "running"
  }

}

/**
  * 声明一个name 属性为public的，age为private的类Human
  * @param name
  * @param age
  */
class Human(val name:String,private val age:Int) extends Animal(age = age){

  var xx=0

  def show(): Unit ={
    printf(s"name:%s\tage:%s\n",name,age)
  }

  override def eat(): Unit = {
    println("--------human eating---------")
  }


}



object Human{

  //通过对象的apply来初始化对象
  def apply( name: String, age: Int): Human = new Human(name, age)
}


object Alive extends App{


  val alive1 = new Human("zhangsan",24)
  val alive2 = new Animal(24)
  alive1.show()
  println(alive1.name)
  Human("HSJKFJSD",25).show()

}